<template>
	<view class='bg-white' style="height: 100vh;">
		<view class="padding-sm solid text-gray text-sm">
			<text class="text-orange">加群：</text> 加客服微信号：<text class="text-blue">{{wechat}}</text>
			<text data-clipboard-action="copy" :data-clipboard-text="wechat" @tap="copy"
				class="copy-btn margin-left-xs margin-right-xs radius cu-btn sm bg-blue">复制</text>
			拉你进驾驶员招聘互助群。
		</view>
		<scroll-view class='bg-white padding padding-top-xs' scroll-y style='height:calc(100vh - 100px)'>
			<view class="padding-xs flex">
				<view class="flex-sub text-lg text-black text-bold">
					{{detail.title}}
				</view>
				<view class="text-red ">
					<template v-if="detail.isTop=='1' ">
					  <template v-if="detail.recruitType==1">{{detail.topTm?'平台急聘':'急聘'}}</template>
											<template v-if="detail.recruitType==0">{{detail.topTm?'平台加急':'加急'}}</template>
					</template>
				</view>
			</view>
			<view class="flex padding-top-sm">
				<view class="flex-sub">
					<text class="text-red">{{detail.salary?detail.salary:'面谈'}}</text> /月
				</view>
				<view class="text-right flex-sub">
					<view class="cu-tag radius line-blue">{{detail.dtypeName}}</view>
					<view v-if="detail.dlTypeName!='不限'" class="cu-tag radius line-blue">{{detail.dlTypeName}} 驾照</view>
				</view>
			</view>
			<view class="padding-top-sm flex text-sm">
				<view class="flex-sub text-gray">
					{{ detail.creTm.substr(0, 10) }} 发布
				</view>
				<view class="text-green text-right flex-sub">
					{{ getPro(detail.areaCode, detail.cityName) }}
				</view>
			</view>

			<view style="line-height: 24px;" class='padding solid margin-top'>
				<view v-html="detail.content"></view>
				<view v-if="detail.linkMan" class="">
					联系人：{{detail.linkMan}}
				</view>
				<view class="text-sm text-gray padding-top-xs" style="line-height: 18px;">
					点击下面拨打电话联系我时，请说明是镖掌柜-专招驾驶员平台上看到的信息，上面的驾驶员靠谱。
				</view>
			</view>
			<view class='margin'>
				<image v-for="(item,index) in detail.infoPicList" :key="index" :data-img="item.picURL" mode='aspectFit'
					@tap="preview" :src="item.picURL"></image>
			</view>
			<view v-if="ancinfoDesc1" class="text-green padding-bottom padding-left padding-right">
				{{ ancinfoDesc1 }}
			</view>
			<view class='padding solid text-sm'>
				<view class='flex'>
					<view class='flex-treble'>
						<text class='text-red'>如遇无效，虚假，已经招满等情况，请联系我们，收到反馈我们会第一时间处理。</text>
						<view class='padding-top'>
							耐心沟通，更好的了解岗位详情，认真核实岗位，符合自己条件的，再考虑上门入职，切勿先付定金。
						</view>
					</view>
					<view class='flex-sub text-center padding-top'>
						<!-- data-uid='{{detail.creID}}' -->
						<button class="cu-btn round line-green" @tap="reportEv">反馈</button>
					</view>
				</view>
			</view>
			<view @tap="navTo(1)" class="margin text-red text-center text-underline">
				点击查看更多招聘求职信息
			</view>
		</scroll-view>
		<view class="cu-bar bg-white tabbar border shop" style="position:fixed;bottom:0;width:100vw;height: 50px;">
			<view class="action" @tap="navTo(1)">
				<view class="cuIcon-home" style="color:#4F9FFF;"></view>首页
			</view>
			<view class="action" @tap="navTo(2)">
				<view class="cuIcon-edit" style="color:#4F9FFF;"></view> 发布
			</view>
			<button style='background:none;color:#666;' class="action" @tap="share">
				<view class="cuIcon-share" style="color:#4F9FFF;"></view>分享
			</button>
			<view class="text-center submit margin-right-xs margin-left-xs"
				style="color:#fff;border-radius:5px;width:95%;background-color: #4F9FFF;margin-bottom:2px;"
				@tap="phoneCall(detail.ancId)">
				<view>
					<view class="text-lg">
						拨打电话
						<view class="text-xs padding-top-xs">
							{{ setPhone(detail.phone) }}
						</view>
					</view>
				</view>

			</view>
		</view>

		<view class="cu-modal" :class="showModal?'show':''">
			<view class="cu-dialog" style="height:100vh;width:100vw;background-color: rgba(0,0,0,0.6);">
				<view class="text-right padding">
					<image src="../../static/arrow.png" style="width: 50px;height: 62px;"></image>
				</view>
				<view class="text-white text-left padding text-xl">
					<view class="">
						1、点击右上角 ... 按钮
					</view>
					<view class="padding-top-sm">
						2、点击发给好友，或分享到朋友圈
					</view>
					<view class="padding-top-sm">
						<template v-if="isVip">
							3、好友点击注册、充值后，您即可获得对应的金币（可提现）收益
						</template>
						<template v-else>
							3、好友点击进入，即可查看该条招聘信息。如果是新用户，您还有可能获得额外的金币收益哦，快去分享吧！
						</template>
					</view>
					<view class="padding text-center margin-top">
						<button @tap="showModal = false" class="bg-green">确 定</button>
					</view>
				</view>
			</view>
		</view>

		<!--
		<view class="cu-modal" :class="showModal?'show':''">
			<view class="cu-dialog">
				<view class="cu-bar bg-white justify-end">
					<view class="content">
						分享内容
					</view>
					<view class="action" @tap="showModal = false">
						<text class="cuIcon-close text-red"></text>
					</view>
				</view>
				<view class="text-left padding-left padding-right bg-white">
					<view v-html="shareContent"></view>
					<view class="text-sm text-gray padding-top-sm">
						点击下面（复制专属链接），发到微信群、QQ群、论坛、贴吧，帮助师傅找到工作，更能获取积分和金币。
					</view>
				</view>
				<view class="cu-bar bg-white justify-end">
					<view class="action">
						<button data-clipboard-action="copy" :data-clipboard-text="shareContent" class="copy-btn cu-btn bg-green margin-left"
						 @tap="copy">复制专属链接</button>
					</view>
				</view>
			</view>
		</view>
		-->
	</view>
</template>

<script>
	import proData from '../../utils/city-data/province.js'
	import Clipboard from 'clipboard'
	import {
		location
	} from '../../utils/util.js'
	export default {
		data() {
			return {
				wechat: '',
				showModal: false,
				shareContent: '',
				code: '',
				province: '',
				getPhone: false,
				phoneData: {
					phone: '',
				},
				isVip: false,
				detail: {
					ancId: '',
					areaCode: "",
					cityName: "",
					content: "",
					creId: 6,
					creTm: "",
					dlTypeId: -1,
					dlTypeName: "不限",
					dtypeId: 2,
					dtypeName: "",
					headPortrait: '',
					infoPicList: [],
					infoPicPathArr: '',
					labIDArr: [],
					labList: [],
					linkMan: "王文华",
					phone: "187****3482",
					recruitType: "1",
					salary: '',
					salary1: '',
					salary2: '',
					title: '',
				},
				ancinfoDesc1:''
			};
		},
		onLoad(option) {
			let u = uni.getStorageSync('ONLINE_USER');
			if ('1' == u.isVip) {
				this.isVip = true
			}
			this.getDetail(option.id);
			if (option.code) {
				this.code = option.code;
			}
			this.getConfig();
		},
		methods: {
			log() {
				// 记录活跃和定位信息
				let data = location();
				let _this = this;
				this.baseRequest('api/dau/log', 'GET', {}, function(res, info) {
					_this.baseRequest('api/dau/log/user', 'POST', {
						areaName: data.attenCity,
						address: data.address
					}, function(res, info) {}, function() {});
				}, function() {});
			},
			getConfig() {
				let config = uni.getStorageSync('config')
				if (config) {
					this.wechat =config.find(v=>v.parmName=='h5_wetchat_detail').value
					this.ancinfoDesc1 =config.find(v=>v.parmName=='h5_ancinfoDesc1').value
				}
			},
			setPhone(phone) {
				return phone.substr(0, 3) + '****' + phone.substr(7, 4);
			},
			// 分享
			share() {
				if (typeof androlua == "undefined") {
					this.showModal = true
				} else {
					let arr = [this.appShareUrl, this.detail.content, '你的好友分享了一条招聘求职信息'];
					androlua.pageGoShare(arr);
					// androlua.pageGoBack();
				}
			},
			dateSub(time) {
				return time.substr(5, 5)
			},
			// 设置城市
			getPro(areaCode, cityName) {
				if (areaCode == '-1' || !areaCode) {
					return '全国';
				}
				areaCode = areaCode.substring(0, 2) + '0000';
				let pro = '';
				for (let i = 0; i < proData.length; i++) {
					if (areaCode == proData[i].value) {
						pro = proData[i].label;
					}
				}
				if (pro == cityName) {
					return cityName;
				} else if (cityName == '不限') {
					return pro;
				} else {
					return pro + ' - ' + cityName;
				}
			},
			reportEv() {
				uni.navigateTo({
					url: '/pages/index/report?id=' + this.detail.ancId
				})
			},

			navTo(type) {
				if (type == "1") {
					uni.switchTab({
						url: '/pages/index/index'
					});
				}
				if (type == "2") {
					uni.switchTab({
						url: '/pages/pub/pub'
					})
				}
			},
			preview() {

			},
			phoneCall(ancId) {
				let _this = this;
				// 判断是否免费
				/*
				let config = uni.getStorageSync('config')
				if (config) {
					if (1 == config.freeAncInfo) {
						uni.makePhoneCall({
							phoneNumber: _this.detail.phone
						})
						this.baseRequest('api/driver/info/phone', 'GET', {
							ancId
						}, function(res, info) {})
						return
					}
				}
				*/
				if (this.getPhone) {
					uni.hideLoading();
					uni.makePhoneCall({
						phoneNumber: _this.phoneData.phone
					})
					return;
				}
				uni.showLoading({
					mask: true,
					title: '号码获取中...'
				})
				this.baseRequest('api/driver/info/phone', 'GET', {
					ancId
				}, function(res, info) {
					uni.hideLoading();
					if (res) {
						_this.getPhone = true;
						_this.phoneData = res;
						_this.detail.phone = _this.phoneData.phone;
						uni.makePhoneCall({
							phoneNumber: _this.phoneData.phone
						})
					} else {
						uni.showToast({
							icon: 'none',
							title: info
						})
					}
				}, function(res) {
					uni.hideLoading();
					if (_this.code) {
						// 跳页面，邀请好友进来的页面
						uni.navigateTo({
							url: '/pages/user/inteuser?id=' + _this.code
						})
						return;
					}
					if (res.code == -100) {
						uni.showModal({
							title: '提示',
							content: res.info,
							success: function(res) {
								if (res.confirm) {
									uni.navigateTo({
										url: '/pages/user/pay'
									})
								} 
							}
						});
					}else{
						uni.showModal({
							title: '提示',
							content: res.info
						});
					}
				});
			},

			getDetail(ancId) {
				let _this = this;
				uni.showLoading({
					title: '请稍候...',
					mask: true
				});
				this.baseRequest('api/driver/info/detail', 'GET', {
					ancId
				}, function(res, info) {
					uni.hideLoading();
					_this.detail = res;
					_this.getPro(res.areaCode);
					_this.setShareHref(res.content);
					_this.detail.content = _this.detail.content.replace(/\n/g, '<br />');
					// _this.log();
				}, function(res) {
					uni.hideLoading();
					setTimeout(() => {
						uni.showToast({
							title: res.info,
							icon: 'none'
						});
						setTimeout(() => {
							uni.hideToast();
							uni.switchTab({
								url: '/pages/index/index'
							})
						}, 1000)
					}, 0);
				});
			},
			// 设置分享链接
			setShareHref(content) {
				let type = this.detail.recruitType == '1' ? '招聘' : '求职';
				let city = this.province + this.detail.cityName + type + '驾驶员。';
				this.shareContent = city + content.substr(0, 150) + '...  点击链接查看详情：';
				let host = window.location.protocol + "//" + window.location.host;
				let id = this.detail.ancId;
				let uri = host + '/pages/index/detail?id=' + id
				let page =uri;

				// 判断邀请码
				let userInfo = uni.getStorageSync('ONLINE_USER');
				if (userInfo) {
					let code = userInfo.invitCode;
					page = page + '&code=' + code;
					this.shareContent += page;
				} else {
					this.shareContent += page;
				}
				this.appShareUrl = page;
				
				let data = {
					title: '你的好友分享了一条' + type + '信息', // 分享标题
					desc: this.shareContent, // 分享描述
					link: page, //添加了code 分享码
					uri:uri
				}
				this.$wx.wxShare(data,function(res){
				}); // 设置分享信息
			},
			copy() {
				let _this = this;
				let clipboard = new Clipboard(".copy-btn");
				clipboard.on('success', function() {
					_this.showModal = false;
					setTimeout(() => {
						uni.showModal({
							title: '恭喜您',
							content: `微信号：${_this.wechat}已复制到粘贴板，去微信-添加朋友-搜索框粘贴`,
							showCancel: false
						});
					}, 500);
				});
				clipboard.on('error', function() {
					_this.showModal = false;
					setTimeout(() => {
						uni.showToast({
							title: '复制失败'
						})
					}, 500);
				});
			}
		}
	}
</script>
